const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    list:{},
    type:'',
    id:0,
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  phone_del(){
    wx.makePhoneCall({
      phoneNumber: '15737321802' // 仅为示例，并非真实的电话号码
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    app.util.request({
      url: 'Index/Index/setOrderDetails',
      data: {
        id: options.id
      },
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        that.setData({
          list:res.data,
          type: options.type,
          id: options.id
        })
      }
    })
  },

  delOrderList:function(e){
    const that = this;
    app.util.request({
      url: 'Index/Index/delOrderList',
      data: {
        id: that.data.list.id
      },
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        wx.showToast({
          title: '删除成功',
          icon: 'success',
          duration: 2000
        });
        wx.navigateBack({
          delta: 1,
        })
      }
    })
  },
  navigation:function(e){
    const that = this;
    const data = that.data.list;
    wx.openLocation({
      latitude: data.order_details.origin_latitude,
      longitude: data.order_details.origin_longitude,
      name: data.order_details.origin,
      address: data.order_details.origin
    })
  },
  navigations:function(e){
    const that = this;
    const data = that.data.list;
    wx.openLocation({
      latitude: data.order_details.terminus_latitude,
      longitude: data.order_details.terminus_longitude,
      name: data.order_details.terminus,
      address: data.order_details.terminus
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  delOrder:function(e){
    const that = this;
    var url = '';
    if (that.data.type === 'myReleaseOrders'){
      url = 'cancelOrder';
    }else{
      url = 'cancelTakeOrder';
    }
    app.util.request({
      url: 'Index/Index/'+url,
      data: {
        id: that.data.id,
        openid: app.globalData.userInfo.openid
      },
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        wx.showToast({
          title: res.data.err_code_des,
          icon: 'success',
          duration: 2000
        });
        wx.navigateBack({
          delta: 1,
        })
      }
    })
    that.setData({
      modalName: null
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})